<?php

/**
 * Class for rendering a link element.
 *
 * @author Ian Clarence <ian.clarence@gmail.com>
 */
class ViewLink extends ViewHtmlElement {

    /**
     * media
     */
    const SCREEN = "screen";
    const TTY = "tty";
    const TV = "tv";
    const PROJECTION = "projection";
    const HANDHELD = "handheld";
    const PRINTER = "print";
    const BRAILLE = "braille";
    const AURAL = "aural";
    const ALL = "all";

    /**
     * rel
     */
    const ALTERNATE = "alternate";
    const APPENDIX = "appendix";
    const BOOKMARK = "bookmark";
    const CHAPTER = "chapter";
    const CONTENTS = "contents";
    const COPYRIGHT = "copyright";
    const GLOSSARY = "glossary";
    const HELP = "help";
    const HOME = "home";
    const INDEX = "index";
    const NEXT = "next";
    const PREV = "prev";
    const SECTION = "section";
    const START = "start";
    const STYLESHEET = "stylesheet";
    const SUBSECTION = "subsection";

    /**
     * Constants for CSS
     */
    const CSS_TYPE = "text/css";
    const CSS_REL = self::STYLESHEET;

    /**
     * The constructor.
     *
     * @param array $fields
     */
    public function __construct(array $fields = array()) {

        $fields["tag"] = "link";
        $fields["type"] = isset($fields["type"]) ? $fields["type"] : self::CSS_TYPE;
        $fields["rel"] = isset($fields["rel"]) ? $fields["rel"] : self::CSS_REL;

        parent::__construct($fields);

        $this->setAttribute("type", $this->getType());
        $this->setAttribute("rel", $this->getRel());

        if (isset($this->fields["href"])) {
            $this->setAttribute("href", $this->getHref());
        }

        if (isset($this->fields["hreflang"])) {
            $this->setAttribute("hreflang", $this->getHreflang());
        }

        if (isset($this->fields["media"])) {
            $this->setAttribute("media", $this->getMedia());
        }

        if (isset($this->fields["charset"])) {
            $this->setAttribute("charset", $this->getCharset());
        }

    }

}